package com.jaws.core.common.initialize;

import javax.annotation.Resource;

import lombok.extern.slf4j.Slf4j;

import org.springframework.boot.CommandLineRunner;

import com.jaws.core.common.log.Log;
import com.jaws.core.common.util.SnowflakeIdK8sUtil;
import com.jaws.core.common.util.SnowflakeIdOldUtil;
import com.jaws.core.common.util.SnowflakeIdUtil;
import com.jaws.core.configuration.CommonProperties;

@Slf4j
public class SnowflakeInitializer implements CommandLineRunner {

	@Resource
	private CommonProperties commonProperties;

	@Override
	public void run(String... args) throws Exception {
		log.info(Log.op("SnowflakeInitializer->CommandLineRunner.run").toString());
		if(commonProperties.isSnowflakeK8s()){
			log.info(Log.op("SnowflakeInitializer.run").kv("snowflake class", "SnowflakeIdK8sUtil").toString());
			SnowflakeIdK8sUtil.init(commonProperties);
			SnowflakeIdUtil.isK8s = true;
		}else{
			log.info(Log.op("SnowflakeInitializer.run").kv("snowflake class", "SnowflakeIdUtil").toString());
			SnowflakeIdOldUtil.init(commonProperties);
			SnowflakeIdUtil.isK8s = false;
		}
	}

}
